<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no">
        <title>微投票</title>
        <link type="text/css" rel="stylesheet" href="./source/modules/vote/style/vote.css" />
        <script type="text/javascript" src="./source/modules/vote/style/js/jquery.js"></script>
        <script type="text/javascript" src="./source/modules/vote/style/js/alert.js"></script>

        <script type="text/javascript">

            document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
                window.shareData = {
                    "imgUrl": "{$shareimg}",
                    "timeLineLink": "{$sharelink}",
                    "sendFriendLink": "{$sharelink}",
                    "weiboLink":  "{$sharelink}",
                    "tTitle":  "{$sharetitle}",
                    "tContent": "{$sharedesc}",
                    "fTitle":  "{$sharetitle}",
                    "fContent": "{$sharedesc}",
                    "wContent": "{$sharedesc}",
                };
                // 发送给好友
                WeixinJSBridge.on('menu:share:appmessage', function (argv) {
                    WeixinJSBridge.invoke('sendAppMessage', {
                        "img_url": window.shareData.imgUrl,
                        "img_width": "640",
                        "img_height": "640",
                        "link": window.shareData.sendFriendLink,
                        "desc": window.shareData.fContent,
                        "title": window.shareData.fTitle
                    }, function (res) {
                        _report('send_msg', res.err_msg);
                    })
                });
                alert( window.shareData.tTitle);
                // 分享到朋友圈
                WeixinJSBridge.on('menu:share:timeline', function (argv) {
                    WeixinJSBridge.invoke('shareTimeline', {
                        "img_url": window.shareData.imgUrl,
                        "img_width": "640",
                        "img_height": "640",
                        "link": window.shareData.timeLineLink,
                        "desc": window.shareData.tContent,
                        "title": window.shareData.tTitle
                    }, function (res) {
                        _report('timeline', res.err_msg);
                    });
                });

                // 分享到微博
                WeixinJSBridge.on('menu:share:weibo', function (argv) {
                    WeixinJSBridge.invoke('shareWeibo', {
                        "content": window.shareData.wContent,
                        "url": window.shareData.weiboLink,
                    }, function (res) {
                        _report('weibo', res.err_msg);
                    });
                });
            }, false)




            var votetype = "{$reply['votetype']}";
            function divClick(obj) {
                obj = $(obj);

                if (votetype == '0') {
                    //单选
                    $(".oimg").show();
                    $(".oimg-sel").hide();
                    $(".option").attr("sel", "false");
                }
                var sel = obj.attr("sel");
                if (sel == "false") {
                    obj.attr("sel", "true");
                    $(".oimg-sel", obj).show();
                    $(".oimg", obj).hide();
                }
                else {
                    obj.attr("sel", "false");
                    $(".oimg-sel", obj).hide();
                    $(".oimg", obj).show();
                }
            }
            function submit() {

                var ids = "";
                $(".option").each(function() {
                    if ($(this).attr("sel") === "true") {
                        if (ids !== "") {
                            ids += ",";
                        }
                        ids += $(this).attr("val");

                    }
                });
                if (ids == '') {
                    alert('请选择投票选项!');
                    return;
                }
                $.ajax({
                    url: "{php echo $this->createMobileUrl('submit', array('id' => $rid))}",
                    data: {
                        t: Math.random(),
                        ids:ids ,
                        id:"{$rid}",
                        from_user:"{$from_user}"
                    },
                    beforeSend: function () {
                       $(".submit").attr("disabled","true");
                    },
                    success: function (data) {
                        
                       if(data!=''){
                           alert(data);
                           return;
                       }
                       alert("投票成功!");
                       $(".submit").removeAttr("disabled");
                       setTimeout(function(){
                           location.href="{php echo $this->createMobileUrl('result', array('id' => $rid))}";
                           
                       },500);
                    },
                    error: function () {
                        
                    },
                    timeout: 15000
                });
			 
      

            }
        </script>
    </head>
    <body>
        <div class="wrapper" style="margin-top:-8px;">
            <img class="bg" src="./source/modules/vote/style/images/bg.jpg">
            <input type='hidden' name='select_id' />
            <div class="top fn-clear">

                <div class="title-cont">
                    <p class="title">{$reply['title']}</p>
                    <p class="timeout" style='padding-left:15px;'><img class="clock" src="./source/modules/vote/style/images/clock.png"><span class="text">{$limits}</span></p>
                    <p>&nbsp;</p>
                </div>
            </div>
            {if !empty($reply['thumb'])}
            <div class="cover">
                <img class="line" src="./source/modules/vote/style/images/ctline.jpg">
                <img class="cimg" src="{php echo img_url($reply['thumb'])}">
                <img class="line" src="./source/modules/vote/style/images/cbline.jpg">
            </div>
            {/if}


            {if $isshare==1}
                <div class="summary">参与方法:</div>
                <div class="tip-cont">{php echo htmlspecialchars_decode($reply['share_txt'])}</div>

            {else}
                <div class="summary">{$reply['description']}</div>
                <div class="tip-cont">
                    <img class="icon" src="./source/modules/vote/style/images/tip_icon.png">
                    投票后才能看到结果 | {$selects} {if !empty($reply['votetimes'])}<br/> 您还可以投票 {$canvotetimes} 次{/if}
                </div>
                <div class="option-cont">
                    {loop $list $row}
                    <div class="option" val="{$row['id']}" onclick="divClick(this)" sel ="false">
                        {if !empty($row['thumb']) && $reply['isimg']==1}
                        <div><image src="{php echo img_url($row['thumb'])}" style="width:95%;margin:10px;" /></div>
                        {/if}
                        <img id="img{$row['id']}" class="oimg" src="./source/modules/vote/style/images/checkimg.png">
                        <img id="img{$row['id']}_sel" class="oimg-sel" src="./source/modules/vote/style/images/checkimg_check.png">

                        <div>{$row['title']}</div>
                    </div>
                    <img class="sep" src="./source/modules/vote/style/images/option_sep.jpg">
                    {/loop}
                </div>

                <div class="vote-cont">
                    <div style="height: 10px;"></div>
                    <img class="vote-btn" src="./source/modules/vote/style/images/vote.png" onclick="submit()"/>
                    <div style="height: 10px;"></div>
                </div>
            {/if}

            <p class="page-url">

            </p>
        </div>
    </body>
</html>
